﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

public class TestAssetBundle : MonoBehaviour
{

    [MenuItem("AssetBundle/Build Windows")]
    static void BuildAssetBundle() {

        string outputPath = Application.streamingAssetsPath;

        if (! Directory.Exists(outputPath) ) {
            Directory.CreateDirectory(outputPath);
        }

        List<AssetBundleBuild> builds = new List<AssetBundleBuild>();

        AssetBundleBuild build = new AssetBundleBuild();
        build.assetBundleName = "ui";
        build.assetBundleVariant = "unity3d";
        build.assetNames = new string[] {"Assets/Prefabs/TestPanel.prefab"
        };

        AssetBundleBuild ui2 = new AssetBundleBuild();
        ui2.assetBundleName = "ui2";
        ui2.assetBundleVariant = "unity3d";
        ui2.assetNames = new string[] {"Assets/Prefabs/TestPanel2.prefab"
        };

        AssetBundleBuild texture = new AssetBundleBuild();
        texture.assetBundleName = "texture";
        texture.assetBundleVariant = "unity3d";
        texture.assetNames = new string[] {"Assets/Texture/logo.png",
            "Assets/Texture/logo_web.png"
        };

        AssetBundleBuild sceneBundles = new AssetBundleBuild();
        sceneBundles.assetBundleName = "scenes";
        sceneBundles.assetBundleVariant = "unity3d";
        sceneBundles.assetNames = new string[] {
            "Assets/Scenes/TestScene.unity",
        };

        builds.Add(build);
        builds.Add(sceneBundles);
        builds.Add(ui2);
        builds.Add(texture);
        BuildPipeline.BuildAssetBundles(outputPath, builds.ToArray() , BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);

    }
    
}
